package com.nuanshui.heatedloan.credit.convert;

import com.nuanshui.heatedloan.credit.constant.CreditConverterType;
import com.nuanshui.heatedloan.credit.facade.PayOrderInfoService;
import com.nuanshui.heatedloan.credit.vo.PayOrderInfoVO;
import com.nuanshui.heatedloan.middleware.convert.Converter;
import com.nuanshui.heatedloan.credit.constant.HomePageConstant;
import com.nuanshui.heatedloan.credit.facade.CustomerProduceService;
import com.nuanshui.heatedloan.credit.model.SingleLoanProductInfo;
import com.nuanshui.heatedloan.credit.vo.CustomerHomePageInfoVO;
import com.nuanshui.heatedloan.middleware.convert.annotation.ConverterAttribute;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@ConverterAttribute(typeId = CreditConverterType.SingleOrderStatusToContent)
public class SingleOrderStatusToContentConverter implements Converter {

    @Autowired
    private CustomerProduceService customerProduceService;

    @Autowired
    private PayOrderInfoService payOrderInfoService;


    @Override
    public Object convert(Object s, Object param) {

        String content=null;

        String userId= (String)param;

        CustomerHomePageInfoVO customerHomePageInfoVO=(CustomerHomePageInfoVO)s;

        if (customerHomePageInfoVO.getValidAmount() >= 0) {

            SingleLoanProductInfo singleLoanProductInfo =customerProduceService.getSingleLoanProductInfo();

            if (customerHomePageInfoVO.getValidAmount() < singleLoanProductInfo.getProductLimit()) {
                content="该产品贷款额度已用完";
            } else {
                content="可贷额度" + (customerHomePageInfoVO.getValidAmount()/100) + "元";
            }
        } else {
            if(customerHomePageInfoVO.getAmount()>0) {
                List<PayOrderInfoVO> list= payOrderInfoService.loadVoRepayByUserId(userId);//针对用户有还款记录
                if (list.size() >0){
                    content="可贷额度" + (customerHomePageInfoVO.getAmount()/100) + "元";
                }else {
                    content=HomePageConstant.SINGLELOAN_AUTH_TEXT_START + (customerHomePageInfoVO.getAmount() / 100) + HomePageConstant.SINGLELOAN_AUTH_TEXT_END;
                }
            } else {
                content="尚未获得额度";
            }
        }
        
        return content;
    }
}
